package com.yi.mall.goods.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yi.mall.common.model.DTO.ProductDetailDTO;
import com.yi.mall.common.utils.ResponseEnum;
import com.yi.mall.common.utils.Result;
import com.yi.mall.common.model.DTO.ProductDTO;
import com.yi.mall.goods.service.impl.ProductServiceImpl;
import com.yi.mall.goods.service.impl.SkuInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/goods/product")
public class ProductController {
    @Autowired
    private SkuInfoServiceImpl skuInfoService;
    @Autowired
    private ProductServiceImpl productService;
    @GetMapping("/list")
    @SentinelResource(value="list", blockHandler = "deal_testHotKey")
     public Result listProducts(ProductDTO productDTO) {
         Page page = new Page();
         page = skuInfoService.page(productDTO);
         return Result.success(ResponseEnum.SUCCESS,page);
     }
    /**
     * 按SPUID获取商品详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        ProductDetailDTO productDetailDTO = productService.queryById(id);
        return Result.success(ResponseEnum.SUCCESS,productDetailDTO);
    }
}
